package com.jwpdk.appframework.data;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

import com.jwpdk.dbframework.DAOBase;

@SuppressWarnings("unchecked")
public class DatasetResult extends DatasetList {

	private static final long	serialVersionUID	= -7655901493987639128L;
	private int					count;

	/**
	 * construct function
	 * @throws Exception
	 */
	public DatasetResult() throws Exception {
		super();
	}

	/**
	 * construct function
	 * @param rs
	 * @throws Exception
	 */
	public DatasetResult(ResultSet rs) throws Exception {
		while ( rs.next() ) {
			ResultSetMetaData rsmd = rs.getMetaData();

			IData data = new DataMap();
			for (int i = 1; i <= rsmd.getColumnCount(); i++) {
				String name = rsmd.getColumnLabel(i).toUpperCase();

				data.put(name,DAOBase.getValueByResultSet(rs,rsmd.getColumnType(i),name));
			}
			add(data);
		}

		count = size();
	}

	/**
	 * get count
	 * @return dint
	 */
	public int count() {
		return count;
	}

	/**
	 * set count
	 * @param count
	 */
	public void setCount(int count) {
		this.count = count;
	}

	/**
	 * clear
	 */
	public void clear() {
		super.clear();
		this.count = 0;
	}

}